package com.lindroy.todomvp.tasks

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.MenuItem
import androidx.core.view.GravityCompat
import com.lindroy.todomvp.R
import com.lindroy.todomvp.util.replaceFragmentInActivity
import com.lindroy.todomvp.util.setupActionBar
import kotlinx.android.synthetic.main.activity_tasks.*

/**
 * @author Lin
 * @date 2021/6/25
 * @function 添加任务页面
 * @Description
 */
class TasksActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_tasks)

        setupActionBar(toolbar){
            setHomeAsUpIndicator(R.drawable.ic_menu)
            setDisplayHomeAsUpEnabled(true)
            title = "待办"
        }

        val tasksFragment = supportFragmentManager.findFragmentById(R.id.contentFrame)
            as TasksFragment? ?: TasksFragment.newInstance().also {
            replaceFragmentInActivity(it, R.id.contentFrame)
        }
    }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        if (item.itemId == android.R.id.home) {
            // Open the navigation drawer when the home icon is selected from the toolbar.
            drawerLayout.openDrawer(GravityCompat.START)
            return true
        }
        return super.onOptionsItemSelected(item)
    }
}